package glz.hawk.bookstore.mapper;

import static glz.hawk.bookstore.mapper.BookDynamicSqlSupport.*;
import static org.mybatis.dynamic.sql.SqlBuilder.isEqualTo;

import glz.hawk.bookstore.model.Book;
import jakarta.annotation.Generated;
import java.math.BigDecimal;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.type.JdbcType;
import org.mybatis.dynamic.sql.BasicColumn;
import org.mybatis.dynamic.sql.delete.DeleteDSLCompleter;
import org.mybatis.dynamic.sql.select.CountDSLCompleter;
import org.mybatis.dynamic.sql.select.SelectDSLCompleter;
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
import org.mybatis.dynamic.sql.update.UpdateDSL;
import org.mybatis.dynamic.sql.update.UpdateDSLCompleter;
import org.mybatis.dynamic.sql.update.UpdateModel;
import org.mybatis.dynamic.sql.util.SqlProviderAdapter;
import org.mybatis.dynamic.sql.util.mybatis3.CommonCountMapper;
import org.mybatis.dynamic.sql.util.mybatis3.CommonDeleteMapper;
import org.mybatis.dynamic.sql.util.mybatis3.CommonInsertMapper;
import org.mybatis.dynamic.sql.util.mybatis3.CommonUpdateMapper;
import org.mybatis.dynamic.sql.util.mybatis3.MyBatis3Utils;

@Mapper
public interface BookMapper extends CommonCountMapper, CommonDeleteMapper, CommonInsertMapper<Book>, CommonUpdateMapper {
    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2025-08-19T10:57:44.5699893+08:00", comments="Source Table: book")
    BasicColumn[] selectList = BasicColumn.columnList(bookId, isbn, bookName, bookType, bookPrice, publishDate, timeSpec, createDate, createUser, bookDescription, bookPicture);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2025-08-19T10:57:44.5638726+08:00", comments="Source Table: book")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    @Results(id="BookResult", value = {
        @Result(column="BOOK_ID", property="bookId", jdbcType=JdbcType.DECIMAL, id=true),
        @Result(column="ISBN", property="isbn", jdbcType=JdbcType.VARCHAR),
        @Result(column="BOOK_NAME", property="bookName", jdbcType=JdbcType.VARCHAR),
        @Result(column="BOOK_TYPE", property="bookType", jdbcType=JdbcType.VARCHAR),
        @Result(column="BOOK_PRICE", property="bookPrice", jdbcType=JdbcType.DECIMAL),
        @Result(column="PUBLISH_DATE", property="publishDate", jdbcType=JdbcType.DATE),
        @Result(column="TIME_SPEC", property="timeSpec", jdbcType=JdbcType.TIME),
        @Result(column="CREATE_DATE", property="createDate", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="CREATE_USER", property="createUser", jdbcType=JdbcType.CHAR),
        @Result(column="BOOK_DESCRIPTION", property="bookDescription", jdbcType=JdbcType.LONGVARCHAR),
        @Result(column="BOOK_PICTURE", property="bookPicture", jdbcType=JdbcType.LONGVARBINARY)
    })
    List<Book> selectMany(SelectStatementProvider selectStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2025-08-19T10:57:44.5652943+08:00", comments="Source Table: book")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    @ResultMap("BookResult")
    Optional<Book> selectOne(SelectStatementProvider selectStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2025-08-19T10:57:44.5652943+08:00", comments="Source Table: book")
    default long count(CountDSLCompleter completer) {
        return MyBatis3Utils.countFrom(this::count, book, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2025-08-19T10:57:44.5665622+08:00", comments="Source Table: book")
    default int delete(DeleteDSLCompleter completer) {
        return MyBatis3Utils.deleteFrom(this::delete, book, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2025-08-19T10:57:44.5665622+08:00", comments="Source Table: book")
    default int deleteByPrimaryKey(BigDecimal bookId_) {
        return delete(c ->
            c.where(bookId, isEqualTo(bookId_))
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2025-08-19T10:57:44.5675882+08:00", comments="Source Table: book")
    default int insert(Book row) {
        return MyBatis3Utils.insert(this::insert, row, book, c ->
            c.map(bookId).toProperty("bookId")
            .map(isbn).toProperty("isbn")
            .map(bookName).toProperty("bookName")
            .map(bookType).toProperty("bookType")
            .map(bookPrice).toProperty("bookPrice")
            .map(publishDate).toProperty("publishDate")
            .map(timeSpec).toProperty("timeSpec")
            .map(createDate).toProperty("createDate")
            .map(createUser).toProperty("createUser")
            .map(bookDescription).toProperty("bookDescription")
            .map(bookPicture).toProperty("bookPicture")
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2025-08-19T10:57:44.5686792+08:00", comments="Source Table: book")
    default int insertMultiple(Collection<Book> records) {
        return MyBatis3Utils.insertMultiple(this::insertMultiple, records, book, c ->
            c.map(bookId).toProperty("bookId")
            .map(isbn).toProperty("isbn")
            .map(bookName).toProperty("bookName")
            .map(bookType).toProperty("bookType")
            .map(bookPrice).toProperty("bookPrice")
            .map(publishDate).toProperty("publishDate")
            .map(timeSpec).toProperty("timeSpec")
            .map(createDate).toProperty("createDate")
            .map(createUser).toProperty("createUser")
            .map(bookDescription).toProperty("bookDescription")
            .map(bookPicture).toProperty("bookPicture")
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2025-08-19T10:57:44.5699893+08:00", comments="Source Table: book")
    default int insertSelective(Book row) {
        return MyBatis3Utils.insert(this::insert, row, book, c ->
            c.map(bookId).toPropertyWhenPresent("bookId", row::getBookId)
            .map(isbn).toPropertyWhenPresent("isbn", row::getIsbn)
            .map(bookName).toPropertyWhenPresent("bookName", row::getBookName)
            .map(bookType).toPropertyWhenPresent("bookType", row::getBookType)
            .map(bookPrice).toPropertyWhenPresent("bookPrice", row::getBookPrice)
            .map(publishDate).toPropertyWhenPresent("publishDate", row::getPublishDate)
            .map(timeSpec).toPropertyWhenPresent("timeSpec", row::getTimeSpec)
            .map(createDate).toPropertyWhenPresent("createDate", row::getCreateDate)
            .map(createUser).toPropertyWhenPresent("createUser", row::getCreateUser)
            .map(bookDescription).toPropertyWhenPresent("bookDescription", row::getBookDescription)
            .map(bookPicture).toPropertyWhenPresent("bookPicture", row::getBookPicture)
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2025-08-19T10:57:44.5713138+08:00", comments="Source Table: book")
    default Optional<Book> selectOne(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectOne(this::selectOne, selectList, book, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2025-08-19T10:57:44.5713138+08:00", comments="Source Table: book")
    default List<Book> select(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectList(this::selectMany, selectList, book, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2025-08-19T10:57:44.5713138+08:00", comments="Source Table: book")
    default List<Book> selectDistinct(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectDistinct(this::selectMany, selectList, book, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2025-08-19T10:57:44.5713138+08:00", comments="Source Table: book")
    default Optional<Book> selectByPrimaryKey(BigDecimal bookId_) {
        return selectOne(c ->
            c.where(bookId, isEqualTo(bookId_))
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2025-08-19T10:57:44.5725348+08:00", comments="Source Table: book")
    default int update(UpdateDSLCompleter completer) {
        return MyBatis3Utils.update(this::update, book, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2025-08-19T10:57:44.5725348+08:00", comments="Source Table: book")
    static UpdateDSL<UpdateModel> updateAllColumns(Book row, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(bookId).equalTo(row::getBookId)
                .set(isbn).equalTo(row::getIsbn)
                .set(bookName).equalTo(row::getBookName)
                .set(bookType).equalTo(row::getBookType)
                .set(bookPrice).equalTo(row::getBookPrice)
                .set(publishDate).equalTo(row::getPublishDate)
                .set(timeSpec).equalTo(row::getTimeSpec)
                .set(createDate).equalTo(row::getCreateDate)
                .set(createUser).equalTo(row::getCreateUser)
                .set(bookDescription).equalTo(row::getBookDescription)
                .set(bookPicture).equalTo(row::getBookPicture);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2025-08-19T10:57:44.5725348+08:00", comments="Source Table: book")
    static UpdateDSL<UpdateModel> updateSelectiveColumns(Book row, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(bookId).equalToWhenPresent(row::getBookId)
                .set(isbn).equalToWhenPresent(row::getIsbn)
                .set(bookName).equalToWhenPresent(row::getBookName)
                .set(bookType).equalToWhenPresent(row::getBookType)
                .set(bookPrice).equalToWhenPresent(row::getBookPrice)
                .set(publishDate).equalToWhenPresent(row::getPublishDate)
                .set(timeSpec).equalToWhenPresent(row::getTimeSpec)
                .set(createDate).equalToWhenPresent(row::getCreateDate)
                .set(createUser).equalToWhenPresent(row::getCreateUser)
                .set(bookDescription).equalToWhenPresent(row::getBookDescription)
                .set(bookPicture).equalToWhenPresent(row::getBookPicture);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2025-08-19T10:57:44.5735528+08:00", comments="Source Table: book")
    default int updateByPrimaryKey(Book row) {
        return update(c ->
            c.set(isbn).equalTo(row::getIsbn)
            .set(bookName).equalTo(row::getBookName)
            .set(bookType).equalTo(row::getBookType)
            .set(bookPrice).equalTo(row::getBookPrice)
            .set(publishDate).equalTo(row::getPublishDate)
            .set(timeSpec).equalTo(row::getTimeSpec)
            .set(createDate).equalTo(row::getCreateDate)
            .set(createUser).equalTo(row::getCreateUser)
            .set(bookDescription).equalTo(row::getBookDescription)
            .set(bookPicture).equalTo(row::getBookPicture)
            .where(bookId, isEqualTo(row::getBookId))
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2025-08-19T10:57:44.5735528+08:00", comments="Source Table: book")
    default int updateByPrimaryKeySelective(Book row) {
        return update(c ->
            c.set(isbn).equalToWhenPresent(row::getIsbn)
            .set(bookName).equalToWhenPresent(row::getBookName)
            .set(bookType).equalToWhenPresent(row::getBookType)
            .set(bookPrice).equalToWhenPresent(row::getBookPrice)
            .set(publishDate).equalToWhenPresent(row::getPublishDate)
            .set(timeSpec).equalToWhenPresent(row::getTimeSpec)
            .set(createDate).equalToWhenPresent(row::getCreateDate)
            .set(createUser).equalToWhenPresent(row::getCreateUser)
            .set(bookDescription).equalToWhenPresent(row::getBookDescription)
            .set(bookPicture).equalToWhenPresent(row::getBookPicture)
            .where(bookId, isEqualTo(row::getBookId))
        );
    }
}
